package com.boot.system.controller;

import com.boot.common.anno.AnnoLog;
import com.boot.common.anno.RepeatSubmit;
import com.boot.common.result.Result;
import com.boot.system.service.DeptService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequiredArgsConstructor
@RestController
@RequestMapping("/dept")
public class DeptController {

    private final DeptService deptService;

    @AnnoLog(value = "部门新增")
    @RepeatSubmit
    @PostMapping("/add")
    public Result<?> addDept(@RequestBody Map<String, Object> dataParam) {
        return deptService.addDept(dataParam);
    }

    @AnnoLog(value = "部门修改")
    @RepeatSubmit
    @PostMapping("/update")
    public Result<?> updateDept(@RequestBody Map<String, Object> dataParam) {
        return deptService.updateDept(dataParam);
    }

    @AnnoLog(value = "部门删除")
    @RepeatSubmit
    @PostMapping("/delete")
    public Result<?> deleteDept(@RequestBody Map<String, Object> dataParam) {
        return Result.success(deptService.deleteDept(Long.valueOf(dataParam.get("id").toString())));
    }

    @AnnoLog(value = "部门列表")
    @PostMapping("/list")
    public Result<?> deptList(@RequestBody Map<String, Object> queryParam) {
        return Result.success(deptService.getDeptList(queryParam));
    }

    @AnnoLog(value = "部门树")
    @GetMapping("/tree")
    public Result<?> deptTree() {
        return Result.success(deptService.getDeptTree());
    }

}
